package com.skhu.as.dao;

import java.util.List;

import org.springframework.jdbc.core.JdbcTemplate;

import com.skhu.as.domain.DutyHours;
import com.skhu.as.mapper.DutyHoursM;

public class DutyHoursD {

	private JdbcTemplate jdbcTemplate;

	public void setJdbcTemplate(JdbcTemplate jdbcTemplate) {
		this.jdbcTemplate = jdbcTemplate;
	}
	
	public List<DutyHours> getDutyHoursList(){
		String sql = "SELECT duty_hours_no, duty_hours FROM duty_hours";
		List<DutyHours> list = jdbcTemplate.query(sql, new DutyHoursM());
		return list;
	}

	public int getDutyHoursMaxNo(){
		String sql = "SELECT MAX(duty_hours_no) FROM duty_hours";
		int maxNo = jdbcTemplate.queryForInt(sql);
		return maxNo;
	}
	
	public int deleteAllDutyHours(){
		String sql = "DELETE FROM duty_hours";
		int result = jdbcTemplate.update(sql);
		return result;
	}
	
	public int insertDutyHours(int dutyHoursNo, String dutyHoursString){
		String sql = "INSERT INTO duty_hours VALUES (?, ?)";
		Object[] param = new Object[]{
				dutyHoursNo,
				dutyHoursString
		};
		int result = jdbcTemplate.update(sql, param);
		return result;
	}
	
}
